import pyautogui
import time
import logging
import pymysql
import socket
import pathlib
import sqlite3
import random
import pyperclip
import json
import os ,sys
from point import *
from loger import *
import platform

winver=platform.win32_ver()
root=pathlib.Path(os.path.dirname(os.path.realpath(sys.argv[0])))
log = Logger('xxgs',StreamLevel='debug',FileLevel='info').logger
root=pathlib.Path(__file__).parent
sqlType="mysql" #sqlite
CorrectRate=0.85
confidence=0.8



def finda(index=0):
    if(type(index)==int):
        # log.info(pic[index])
        p=pyautogui.locateOnScreen(str(root/pic[index]),confidence=confidence)
    else:
        # log.info(index)
        p=pyautogui.locateOnScreen(str(root/index),confidence=confidence)
    return (p)
def findClick(index):
    p=finda(index)
    if(p== None):
        log.debug(f"Unable to find {index}")
        return False
    else:
        pyautogui.moveTo(pyautogui.center(p))
        time.sleep(0.5)
        pyautogui.click()
        return True
if __name__ == "__main__":
    # getclasshour()
    while(1):
        try:
            if(findClick("xxgs.png")):
                 log.info("clicked!")
        except:
            log.error("findClick error")
        time.sleep(5)